/**
* AutoSWF - Cody Cushing. March 26, 2009
* Copyright (c) 2009 Cody Cushing
* No use restrictions. Maintain this notice in all versions. 
**/

package com.autoswf.dispatcher
{
	import com.autoswf.core.Transport;


	/**
	 * Lets nodes down the chain register listeners for events passing through this node.
	 */
	public class RemoteDispatcher extends LinkDispatcher
	{
		/**
		 * Constructor.
		 */
		public function RemoteDispatcher(id:String)
		{
			super(id);
		}
		
		
		/** Checks for Listeners traversing the graph to add them to this event dispatcher. */
		override public function sendUp(object:*):void
		{
			var transport:Transport = (object is Transport) ? object : new Transport(object);
			
			if(transport is RemoteListener)
			{
				var listener:RemoteListener = RemoteListener(transport);
				if(listener.removeListener) /* If the arguments are for removing a listener */
				{
					_dispatcher.removeEventListener.apply(null, listener.arguments);
				}
				else /* the arguments are for adding a listener */
				{
					_dispatcher.addEventListener.apply(null, listener.arguments);
				}
				return;
			}
			
			super.sendUp(transport);
		}
	}
}